package org.ws.edu.common.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "profiles")
public class Profile extends Identify {

    private String name;
    private String passwordHash;
    private Double rating;
    private ProfileType type;
    private Profile company;
    private Set<Profile> employees;
    private Set<Appointment> appointments;

    @Column(name = "profile_name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "profile_rating")
    public Double getRating() {
        return rating;
    }

    public void setRating(Double rating) {
        this.rating = rating;
    }

    @Enumerated(EnumType.STRING)
    @Column(name = "profile_type")
    public ProfileType getType() {
        return type;
    }

    public void setType(ProfileType type) {
        this.type = type;
    }

    @OneToOne(cascade = CascadeType.ALL)
    public Profile getCompany() {
        return company;
    }

    public void setCompany(Profile company) {
        this.company = company;
    }

    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "profile_employees", joinColumns = { @JoinColumn(name = "profile_id") }, inverseJoinColumns = { @JoinColumn(name = "employee_id") })
    public Set<Profile> getEmployees() {
        return employees;
    }

    public void setEmployees(Set<Profile> employees) {
        this.employees = employees;
    }

    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "Profile_Appointments", joinColumns = { @JoinColumn(name = "profile_id") }, inverseJoinColumns = { @JoinColumn(name = "appointment_id") })
    public Set<Appointment> getAppointments() {
        return appointments;
    }

    public void setAppointments(Set<Appointment> appointments) {
        this.appointments = appointments;
    }

    @Override
    @Id
    @GeneratedValue
    @Column(name = "profile_id")
    public Long getId() {
        return super.getId();
    }

    @Column(name = "profile_password_hash")
    public String getPasswordHash() {
        return passwordHash;
    }

    public void setPasswordHash(String passwordHash) {
        this.passwordHash = passwordHash;
    }

}
